#pragma once
#include <GL/glew.h>
#include "utilities.h"
#include "ilcontainer.h"
#include "window.h"
#include "planar_mesh.h"
#include "shader.h"
#include "glm/glm.hpp"

#ifndef LAMP_H
#define LAMP_H
class Lamp
{
public:
	Lamp(void)
	{
		x = 0;
		y = 0;
		width = 100;
		height = 100;
		this->planar_mesh = NULL;
		this->wireframe = false;
		this->draw_normals = false;
		this->do_flat_shading = false;
		this->force_open = false;
		this->InitializeGLHandles();
		this->do_normal_mapping = false;
	};

	void Display(void);

	bool PostGLInitialize(void);

	void ApplyCustomization(float (* function)(float));
	
	void Axes()
	{
		GLboolean lighting_is_enabled = glIsEnabled(GL_LIGHTING);
		glDisable(GL_LIGHTING);
		glBegin(GL_LINES);
		glColor3f(1.0f, 0.0f, 0.0f);
		glVertex3f(0.0f, 0.0f, 0.0f);
		glVertex3f(1.0f, 0.0f, 0.0f);
		glColor3f(0.0f, 1.0f, 0.0f);
		glVertex3f(0.0f, 0.0f, 0.0f);
		glVertex3f(0.0f, 1.0f, 0.0f);
		glColor3f(0.0f, 0.0f, 1.0f);
		glVertex3f(0.0f, 0.0f, 0.0f);
		glVertex3f(0.0f, 0.0f, 1.0f);
		glEnd();
		if (lighting_is_enabled)
			glEnable(GL_LIGHTING);
	}

		PlanarMesh * planar_mesh;
	Shader fragment_shader;
	Shader vertex_shader;
	Shader * shader;

	GLuint vertex_coordinate_handle;
	GLuint normal_value_handle;
	GLuint texture_coordinate_handle;
	GLuint vertex_array_handle;

	GLuint endcap_coordinate_handle;
	GLuint endcap_normal_handle;
	GLuint endcap_vertex_array_handle;

	ILContainer skybox_container;
	ILContainer normal_map_container;
	ILContainer second_normal_map_container;

	std::vector<glm::vec3> endcap_coordinates;
	std::vector<glm::vec3> endcap_normals;
	std::vector<glm::uint> endcap_triangle_indices;

	bool wireframe;
	bool draw_normals;
	bool do_flat_shading;
	bool force_open;
	bool do_normal_mapping;

	GLsizei width;
	GLsizei height;
	GLuint window_handle;
	GLint period;
	GLsizei x;
	GLsizei y;

private:
	void InitializeGLHandles()
	{
		this->vertex_array_handle = BAD_GL_VALUE;
		this->vertex_coordinate_handle = BAD_GL_VALUE;
		this->texture_coordinate_handle = BAD_GL_VALUE;
		this->normal_value_handle = BAD_GL_VALUE;
		this->endcap_coordinate_handle = BAD_GL_VALUE;
		this->endcap_normal_handle = BAD_GL_VALUE;
		this->endcap_vertex_array_handle = BAD_GL_VALUE;
	}
};

float LampRad(float);
#endif